﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using System.Web.UI.WebControls;

namespace Web.Class
{
    public class TestDataManager
    {
        public static void InsertDataToGridView(GridView gv, List<string[]> rowList, int emptyRowCount)
        {
            var dt = new DataTable();
            try
            {
                for (var i = 0; i < gv.Columns.Count; i++)
                    dt.Columns.Add(new DataColumn("C" + i));
                for (var i = 0; i < rowList.Count; i++)
                {
                    var dr = dt.NewRow();
                    for (var j = 0; j < rowList[i].Length; j++)
                        dr[j] = rowList[i][j];
                    dt.Rows.Add(dr);
                }

                for (var i = 0; i < emptyRowCount; i++)
                {
                    var drEmpty = dt.NewRow();
                    for (var j = 0; j < drEmpty.ItemArray.Length; j++)
                        drEmpty[j] = "";
                    dt.Rows.Add(drEmpty);
                }
            }
            catch (Exception EX_NAME)
            {
                Console.WriteLine(EX_NAME);
            }

            gv.DataSource = dt;
            gv.DataBind();
        }

        public static void HidenColumns(GridView gv, int[] hColumnIndexs)
        {
            for (var i = 0; i < hColumnIndexs.Length; i++)
                gv.Columns[hColumnIndexs[i]].Visible = false;
        }

        private static string replaceStrToSpace(string text)
        {
            var rs = new StringBuilder();
            for (var i = 0; i < text.Length; i++)
                if (text[i] > 127 && text[i] != '³')
                    rs.Append(text[i].ToString());
            return rs.ToString();
        }
    }
}